﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ConfigMeister
{
    public partial class TriangleBox : Form
    {
        public TriangleBox(Triangle mod)
        {
            InitializeComponent();

            textBox1.Text = mod.Name;

            numericUpDown9.Value = (decimal) mod.PointA.X;
            numericUpDown10.Value = (decimal)mod.PointA.Y;
            numericUpDown11.Value = (decimal)mod.PointA.Z;

            numericUpDown3.Value = (decimal)mod.PointB.X;
            numericUpDown2.Value = (decimal)mod.PointB.Y;
            numericUpDown1.Value = (decimal)mod.PointB.Z;

            numericUpDown6.Value = (decimal)mod.PointC.X;
            numericUpDown5.Value = (decimal)mod.PointC.Y;
            numericUpDown4.Value = (decimal)mod.PointC.Z;

            numericUpDown12.Value = (decimal) mod.CoordA.U;
            numericUpDown7.Value = (decimal)mod.CoordA.V;

            numericUpDown13.Value = (decimal)mod.CoordB.U;
            numericUpDown8.Value = (decimal)mod.CoordB.V;

            numericUpDown15.Value = (decimal)mod.CoordC.U;
            numericUpDown14.Value = (decimal)mod.CoordC.V;
            

            comboBox4.Items.AddRange(MaterialBucket.GetList());
            if (MaterialBucket.Count > 0)
            {
                if (mod.Material != "")
                {
                    comboBox4.SelectedItem = mod.Material;
                }
                else
                {
                    comboBox4.SelectedIndex = 0;
                }
                return;
            }
            comboBox4.Enabled = false;
        }

        public Triangle Result
        {
            get
            {
                Triangle mod = new Triangle();

                textBox1.Text = mod.Name;

                mod.PointA.X = (double) numericUpDown9.Value;
                mod.PointA.Y = (double) numericUpDown10.Value;
                mod.PointA.Z = (double) numericUpDown11.Value;

                mod.PointB.X = (double) numericUpDown3.Value;
                mod.PointB.Y = (double) numericUpDown2.Value;
                mod.PointB.Z = (double) numericUpDown1.Value;

                mod.PointC.X = (double) numericUpDown6.Value;
                mod.PointC.Y = (double) numericUpDown5.Value;
                mod.PointC.Z = (double) numericUpDown4.Value;

                mod.CoordA.U = (double) numericUpDown12.Value;
                mod.CoordA.V = (double) numericUpDown7.Value;

                mod.CoordB.U = (double) numericUpDown13.Value;
                mod.CoordB.V = (double) numericUpDown8.Value;

                mod.CoordC.U = (double) numericUpDown15.Value;
                mod.CoordC.V = (double) numericUpDown14.Value;

                mod.Material = comboBox4.SelectedItem.ToString();

                return mod;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (MaterialBucket.Count == 0)
            {
                MessageBox.Show("Nie istnieją żadne materiały. Zostanie utworzony i przypisany domyślny materiał. Materiały możesz edytować w Edytorze materiałów.", "Brak materiału");
                Material temp = new Material();
                MaterialBucket.Add(temp);
                comboBox4.Items.AddRange(MaterialBucket.GetList());
                comboBox4.SelectedIndex = 0;
            }

            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
